﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AppManagement.Repositories;
using AppManagement.Helpers;

namespace AppManagement.Reports
{
    public partial class FrmInPhieuNhapKho : Form
    {
        public DateTime NgayNhapKho { get; set; }
        public string NhaCungCap { get; set; }
        public int IDPhieuNhapKho { get; set; }

        public FrmInPhieuNhapKho()
        {
            InitializeComponent();
        }

        public void LoadData()
        {
            var dt = new DataTable();
            dt.Columns.Add("STT");
            dt.Columns.Add("ID");
            dt.Columns.Add("TEN_THIET_BI");
            dt.Columns.Add("SO_LUONG");

            var lst = CHITIETPHIEUNHAPKHORepository.SelectByPHIEU_NHAP_KHO_ID(IDPhieuNhapKho);

            for (int i = 0; i < lst.Count; i++)
            {
                dt.Rows.Add((i + 1).ToString(), lst[i].THIET_BI_ID, lst[i].THIETBI.TEN_THIET_BI, lst[i].SO_LUONG);
            }

            rptChiTietPhieuNhapKho rpt = new rptChiTietPhieuNhapKho();
            rpt.DataDefinition.FormulaFields["NgayNhapKho"].Text = "'" + String.Format("{0:dd/MM/yyyy}", NgayNhapKho) + "'";
            rpt.DataDefinition.FormulaFields["NhaCungCap"].Text = "'" + NhaCungCap + "'";
            rpt.DataDefinition.FormulaFields["NguoiLapPhieu"].Text = "'" + PHIEUNHAPKHORepository.SelectByID(IDPhieuNhapKho).NGUOIDUNG.TEN_NGUOI_DUNG + "'";

            rpt.SetDataSource(dt);
            crystalReportViewer1.ReportSource = rpt;
        }

        private void FrmInPhieuNhapKho_Load(object sender, EventArgs e)
        {
            LoadData();
        }
    }
}
